// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        _lbName: null, //姓名
        _lbGold: null, //金币
        _smilePos: null, //表情坐标
        _headSpr: null, //头像
        _imgPiao: null, //漂分  
        _imgSound: null, //声音
        _iconReady: null, //准备
        _iconBanker: null, //庄家标记
        _ipNode: null, //IP地址
        _waitPos: null, //等待时的坐标
        _gamePos: null, //游戏时的坐标  
        _nameStr: null, //当前显示的玩家的名字
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad: function () {
        this.node.zIndex = 100;
        this._lbName = this.node.getChildByName('name').getComponent(cc.Label);
        this._lbGold = this.node.getChildByName('point').getComponent(cc.Label);
        this._imgPiao = this.node.getChildByName('img_piao');
        this._imgSound = this.node.getChildByName('icon_saysound');
        this._iconReady = this.node.getChildByName('icon_ready');
        this._iconBanker = this.node.getChildByName('icon_banker');

        this._headSpr = this.node.getChildByName('head');
        if (this._headSpr == null) {
            var childs = this.node.getChildren();
            for (var i = 0; i < childs.length; i++) {
                if (childs[i].getChildByName('head')) {
                    this._headSpr = childs[i].getChildByName('head').getComponent('WebImage');
                    break;
                }
            }
        }
        this._gamePos = this.node.getPosition();
        if (this._waitPos == null)
            this._waitPos = this.node.getPosition();
        if (this._iconBanker)
            this._iconBanker.active = false;
        if (this._iconReady)
            this._iconReady.active = false;
        if (this._imgSound)
            this._imgSound.active = false;
        if (this._imgPiao)
            this._imgPiao.active = false;
    },

    setWaitPos: function (pos) {
        this._waitPos = pos;
    },

    waitForStart: function () {
        this.node.setPosition(this._waitPos);
    },

    moveToGamePos: function (isAnim) {
        if (this.node.x != this._gamePos.x || this.node.y != this._gamePos.y) {
            this.node.stopAllActions();
            if (isAnim) {
                this.node.runAction(cc.moveTo(0.1, this._gamePos.x, this._gamePos.y));
            } else {
                this.node.setPosition(this._gamePos);
            }
        }
        // if (this._lbName.width > 150 && this.mNameStr && this.mNameStr.length > 0) {
        //     this._lbName.string = this.mNameStr.substring(0, 5) + '...';
        // }
    },

    setIsReady: function (ready) {
        this._iconReady.active = ready;
    },

    setQuickState: function (state) {

    },

    setOffLine: function (offline) {

    },

    setIpArr: function (ipArr) {

    },

    setIsBanker: function (isbanker) {
        if (this._iconBanker)
            this._iconBanker.active = isbanker;
    },

    setPiao: function () {

    },

    setGold: function (gold) {
        this._lbGold.string = gold;
    },

    setPlayer: function (p) {
        this.node.active = true;
        this._lbName.string = p.m_szNikeName;
        this._lbGold.string = p.m_point;

        this.setIsReady(p.m_boReady);
        this.setOffLine(p.m_btOffline);
        this.setIpArr(p.m_ipArr);
        this._headSpr.initWithFileUrl(p.m_headUrl, p.m_btSex, p.m_dbid);
        p.setGameFace(this);
    },

    init: function () {

    },

    start: function () {

    },

    // update (dt) {},
});